﻿package src {
	
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.system.System;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.Timer;
	
	/**
	 * Info tab
	 * @author Indrek Tamming
	 */
	public class InfoTab extends Tab {
		
		/**
		 * Callback to the Viewer
		 */
		private var cb:Viewer;
		
		/**
		 * String with total memory as text
		 */
		private var totalMemory:String;
		
		/**
		 * Init the info tab
		 * @param	cb
		 */
		public function InfoTab(cb:Viewer):void {
			this.cb = cb;
			totalMemory = String(System.totalMemory);
			var timer:Timer = new Timer(10000);
			timer.addEventListener(TimerEvent.TIMER, timerTick);
			timer.start();
		}
		
		/**
		 * Timer event to update the memory string
		 * @param	e
		 */
		private function timerTick(e:TimerEvent):void {
			totalMemory = String(System.totalMemory);
			draw();
		}
		
		/**
		 * Draw the tab
		 */
		public function draw():void {
			while (this.numChildren > 0) this.removeChildAt(0);
			
			var tf:TextField = new TextField();
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.text = totalMemory + "bytes \n of memory used";
			addChild(tf);
		}
		
	}
	
}